package com.lvyq.util;

import java.util.Date;

/**
 * @program: weg
 * @description:
 * @author: lvyq
 * @create: 2023-04-07 22:04
 **/
public class DateUtil {
    
    /** 
    * @Description: 时间转换 天 时 分 秒
    * @params:  * @param 
    * @return: {@link java.lang.String}
    * @Author: lvyq
    * @Date: 2023/4/7 22:05
    */
    public static final String timeChange(long endTime){
        String time="";
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endTime-new Date().getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        long sec = diff % nd % nh % nm / ns;
        if (day>0){
            time=day + "天" + hour + "小时" + min + "分钟"+sec+"秒";
        }else if (hour>0){
            time= hour + "小时" + min + "分钟"+sec+"秒";
        }else if (min>0){
            time=min + "分钟"+sec+"秒";
        }else if (sec>0){
            time=sec+"秒";
        }
        return time;
    }

    public static final String getTime(long endTime){
        String time="";
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endTime;
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        long sec = diff % nd % nh % nm / ns;
        StringBuffer buffer = new StringBuffer();
        if (day>0){
            buffer.append(day + "天");
        }else if (hour>0){
            buffer.append(hour + "小时");
        }else if (min>0){
            buffer.append(min + "分钟");
        }else if (sec>0){
            buffer.append(sec+"秒");
        }
        time=buffer.toString();
        return time;
    }
}
